{extend name="public:base" /}{block name="css"}
<link href="/static/laydate/theme/default/laydate.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css" rel="stylesheet"/>{/block}{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h3>总订单支付金额：{$all_pay_price}元</h3>
                </div>

                <div class="ibox-content">
                    <div class="row search-form">
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择开始日期" type="text" name="start_time" value="{:input('start_time')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择结束日期" type="text" name="end_time" value="{:input('end_time')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="status" class="form-control form-control-lg">
                                    <option value="">请选择订单状态</option>
                                    <option value="1" {:input(
                                    'status') == 1 ? 'selected' : ''}>待付款</option>
                                    <option value="2" {:input(
                                    'status') == 2 ? 'selected' : ''}>待发货</option>
                                    <option value="3" {:input(
                                    'status') == 3 ? 'selected' : ''}>待收货</option>
                                    <option value="4" {:input(
                                    'status') == 4 ? 'selected' : ''}>待评价</option>
                                    <option value="5" {:input(
                                    'status') == 5 ? 'selected' : ''}>已完成</option>
                                    <option value="6" {:input(
                                    'status') == 6 ? 'selected' : ''}>售后中</option>
                                    <option value="7" {:input(
                                    'status') == 7 ? 'selected' : ''}>售后完成</option>
                                    <option value="8" {:input(
                                    'status') == 8 ? 'selected' : ''}>已取消</option>
                                    <option value="9" {:input(
                                    'status') == 9 ? 'selected' : ''}>待自提</option>
                                    <option value="10" {:input(
                                    'status') == 10 ? 'selected' : ''}>待核销</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="after_status" class="form-control form-control-lg">
                                    <option value="">请选择订单售后状态</option>
                                    <option value="0" {:input(
                                    'after_status') == 0 && input('after_status') !='' ? 'selected' : ''}>未售后</option>
                                    <option value="1" {:input(
                                    'after_status') == 1 ? 'selected' : ''}>售后中</option>
                                    <option value="2" {:input(
                                    'after_status') == 2 ? 'selected' : ''}>售后成功</option>
                                    <option value="3" {:input(
                                    'after_status') == 3 ? 'selected' : ''}>售后失败</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请输入订单号" type="text" value="{:input('order_sn')}" class="form-control form-control-lg" name="order_sn">
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
<!--                                <button type="button" class="btn btn-primary btn-lg excel-btn">导出</button>-->
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <button href="{:url('allOrderSend')}" type="button" style="height: 2.1rem; margin-left: 10px" class="btn btn-primary btn-lg ajax-operate">一键配送</button>
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th width="2%">ID</th>
                                <th width="5%">会员昵称</th>
                                <th width="5%">订单号</th>
                                <th width="5%">总金额</th>
                                <th width="5%">支付金额</th>
                                <th width="14%">预约用餐时间</th>
                                <th width="14%">商品信息</th>
                                <th width="20%">收货信息</th>
                                <th width="5%">订单状态</th>
                                <th width="5%">售后状态</th>
                                <th width="10%">创建时间</th>
                                <th width="10%">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.username}</td>
                                <td>{$vo.order_sn}</td>
                                <td>{$vo.all_price}</td>
                                <td>{$vo.pay_price}</td>
                                <td>{$vo.is_business == 1 ? $vo.arrive_time : ''}</td>
                                <td>
                                    {volist name="$vo.vice_order_list" id="v"}
                                    {$v.name} x {$v.count}<br />
                                    {/volist}
                                    {if $vo.lottery_price == 0 && $vo.lottery_coupon_name}
                                    <span style="color: red">实物券：{$vo.lottery_coupon_name}</span>
                                    {/if}
                                </td>
                                <td>
                                    {if $vo.send_type == 1}
                                    姓名：{:mb_substr($vo.get_username, 0, 1)}{$vo.get_sex == 1 ? '先生' : '女士'}<br/>
                                    手机号：{$vo.get_mobile}<br/>
                                    地址：{$vo.get_address}<br/>
                                    配送距离：{$vo.distance}
                                    {elseif $vo.send_type == 2 /}
                                    自取订单
                                    {else /}
                                    堂食订单
                                    {/if}
                                </td>
                                <td>{$vo.status_text}</td>
                                <td>{$vo.after_status_text}</td>
                                <td>{:timeFormat($vo.create_time)}</td>
                                <td class="project-actions">
                                    {if $vo.status == 2}
                                    <a href="javascript: void(0)" data-toggle="modal" data-target="#myModal3" onclick="cancelOrder({$vo.id})" class="btn btn-white btn-sm">
                                        <i class="iconfont icon-close"></i> 取消订单
                                    </a>
                                    <!--
                                     || ($vo.is_business == 1 && isTimeInRange(date('Y-m-d H:m'), $vo.arrive_time)))
                                    -->
                                    {if $vo.businessOrderShowSendBtn}
                                    <a href="{:url('doOrder', ['id' => $vo.id])}" class="btn btn-white btn-sm ajax-operate">
                                        <i class="iconfont icon-31quanbushangpin"></i> 开始配送
                                    </a>
                                    {/if}
                                    {/if}
                                    <a href="{:url('doOrder', ['id' => $vo.id])}" class="btn btn-white btn-sm">
                                        <i class="iconfont icon-edit"></i> 详情
                                    </a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>

                </div>
            </div>
        </div>

    </div>

    <div class="modal inmodal" id="myModal3" tabindex="-1" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" onclick="modelClose()"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">取消订单</h4>
                </div>
                <div class="modal-body">
                    <input type="text" class="form-control cancel_reason" placeholder="请输入原因" value="超出配送距离">
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-white" onclick="modelClose()">关闭</button>
                    <button type="button" class="btn btn-primary" id="confirm">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script src="/static/laydate/laydate.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>
<script>
    laydate.render({
        elem: '.screen-date' //指定元素
    });

    $('#select2').select2()

    var id = 0;

    function cancelOrder(order_id) {
        id = order_id;
    }

    function modelClose() {
        $('body').removeClass('modal-open');
        $('.modal-backdrop').remove();
        $('#myModal3').css('display', 'none').removeClass('show');
        id = 0;
    }

    $('#confirm').click(function () {
        var cancel_reason = $('.cancel_reason').val();

        var url = "/index/Api/platformCancelOrder";
        $.post(url, {
            id, cancel_reason
        }, function (res) {
            layer.msg(res.msg)
            if (res.result == 1) {
                modelClose();
                window.location.reload();
            }
        }, 'json')
    })

    $('.ajax-operate').click(function () {
        var url = $(this).attr("href");

        swal({
            title: "您确认要执行该操作吗？",
            type: "warning",
            cancelButtonText: '取消',
            showCancelButton: true,
            confirmButtonColor: "#1BBF80",
            confirmButtonText: "确认",
            closeOnConfirm: false
        }, function () {
            // 加载层
            var index = layer.load(2, {shade: [0.2, '#000']});

            $.post(url, function (res) {
                if (res.result == 1) {
                    setTimeout(function () {
                        window.location.href = res.url;
                    }, res.timer)
                } else if (res.result == 2) {
                    layer.close(index);
                    layer.msg(res.msg);
                }
            }, 'json');

            setTimeout(function () {
                layer.close(index);
            }, 3000)
        });
        return false;
    })
</script>{/block}

